﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HR.ProjectX.DAL.UnitOfWork;
using NHibernate;
using HR.ProjectX.DAL.SessionStorage;
using HR.ProjectX.Models.Entities.Customers;

namespace HR.ProjectX.DAL.Repositories
{
    public class CustomerRepository : Repository<Customer, int>, ICustomerRepository
    {
        public CustomerRepository(IUnitOfWork uow)
            : base(uow)
        {
        }

        public Customer FindCustomerByEmail(string email)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                    .CreateCriteria(typeof(Customer))
                    .Add(NHibernate.Criterion.Restrictions.Eq("CustomerEmail", email));

            return (Customer)criteriaQuery.List<Customer>().FirstOrDefault();
        }
    }
}
